package com.heima.article.controller;

import com.heima.article.dto.ArticleDto;
import com.heima.article.dto.ArticleHomeDto;
import com.heima.article.dto.ArticleInfoDto;
import com.heima.article.service.IApArticleService;
import com.heima.common.dto.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 文章信息表，存储已发布的文章 前端控制器
 * </p>
 *
 * @author Wq
 * @since 2022-10-11
 */
@RestController
@RequestMapping("/api/v1/article")
@Api(tags = "文章信息表，存储已发布的文章接口")
@CrossOrigin
public class ApArticleController {

    @Autowired
    private IApArticleService apArticleService;


    /**
     * 保存文章
     *
     * @param dto dto
     * @return {@code ResponseResult<Long>}
     */
    @PostMapping
    public ResponseResult<Long> saveArticle(@RequestBody ArticleDto dto) {
        return apArticleService.saveArticle(dto);
    }

    /**
     * app端文章列表查询
     *
     * @return {@code ResponseResult}
     */
    @PostMapping(value = "/load",name = "首次加载")
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {
        return apArticleService.load(dto,0);
    }


    @PostMapping(value = "/loadnew",name = "加载最新")
    public ResponseResult loadnew(@RequestBody ArticleHomeDto dto) {
        return apArticleService.load(dto,1);
    }

    @PostMapping(value = "/loadmore",name = "加载更多")
    public ResponseResult loadmore(@RequestBody ArticleHomeDto dto) {
        return apArticleService.load(dto,2);
    }

    /**
     * 加载文章详情信息
     *
     * @param dto dto
     * @return {@code ResponseResult}
     */
    @PostMapping("/load_article_info")
    @ApiOperation(value = "加载文章详情信息", notes = "加载文章详情信息")
    @ApiImplicitParam(name = "dto",  dataType = "ArticleInfoDto")
    public ResponseResult loadArticleInfo(@RequestBody ArticleInfoDto dto) {
        return apArticleService.loadArticleInfo(dto);
    }
}
